<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessBackpig */

$this->title = $model->number;
$this->params['breadcrumbs'][] = ['label' => 'Business Backpigs', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
            <?= Html::a('返回','javascript:history.back(-1)'); ?>
            <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">

                <div class="business-backpig-view">

                    <p>
                        <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
                        <?= Html::a('删除', ['delete', 'id' => $model->id], [
                            'class' => 'btn btn-danger',
                            'data' => [
                                'confirm' => '您确定删除此项吗?',
                                'method' => 'post',
                            ],
                        ]) ?>
                    </p>

                    <?= DetailView::widget([
                        'model' => $model,
                        'attributes' => [
                            'id',
                            'pigno',
                            'farmername',
                            'grossweight',
                            'backprice',
                            [
                                'attribute' => 'createtime',
                                'value' => function($model){
                                    return date('Y-m-d',$model->createtime);
                                }
                            ],
                            [
                                'attribute' => 'status',
                                'value' => function($model){
                                    return \common\models\business\BusinessBackpig::$statues[$model->status];
                                }
                            ],
                        ],
                    ]) ?>
                    <div class="row">
                        <div class="col-md-10 col-md-offset-1">
                            <table class="table table-striped" id="cost">
                                <tr>
                                    <th>成本类型</th>
                                    <th>金额</th>
                                    <th>时间</th>
                                    <th>上报人员</th>
                                    <th>状态</th>
                                </tr>
                                <?php $total = 0; ?>
                                <?php foreach ($cost as $key => $row) {?>
                                    <?php $total += $row['price']; ?>
                                    <tr class="costdata">
                                        <td><?= $row['type'] ?></td>
                                        <td><?= $row['price'] ?></td>
                                        <td><?= $row['createtime'] ?></td>
                                        <td><?= $row['person'] ?></td>
                                        <td><?= $row['status'] ?></td>
                                    </tr>
                                <?php } ?>
                                <tr class="costdata">
                                    <td><b>成本总计</b></td>
                                    <td><b><?= $total ?>元</b></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr class="costdata">
                                    <td><b>总计(回购价格+成本)</b></td>
                                    <td><b><?= $total + ($model->grossweight*$model->backprice)?>元</b></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>

                            </table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>
</section>